<template>
  <div>
    <el-table
      fit
      :data="tableData"
      style="width: 100%"
      :header-cell-style="{
        background: '#3d80f2',
        color: '#fff',
        fontSize: '16px',
        height: '55px',
      }"
    >
      <!-- <el-table-column prop="numbering" label="编号"></el-table-column> -->
      <el-table-column prop="title" label="姓名">
        <template slot-scope="scope">
          <el-input
            v-model="scope.row.title"
            placeholder="请输入姓名"
            style="100px"
          ></el-input>
        </template>
      </el-table-column>
      <el-table-column prop="trainingType" label="性别">
        <template slot-scope="scope">
          <el-select v-model="scope.row.trainingType" placeholder="请选择性别">
            <el-option label="男" value="nan"></el-option>
            <el-option label="女" value="nv"></el-option>
          </el-select>
          <!-- <el-input
            placeholder=""
            v-model="scope.row.trainingType"
            placeholder="请选择"
            clearable
          ></el-input> -->
        </template>
      </el-table-column>
      <el-table-column prop="trainingForm" label="身份证">
        <template slot-scope="scope">
          <el-input
            v-model="scope.row.trainingForm"
            multiple
            placeholder="请选择"
          >
          </el-input>
        </template>
      </el-table-column>
      <el-table-column prop="trainingPlanTime" label="年龄">
        <template slot-scope="scope">
          <el-input
            v-model="scope.row.trainingPlanTime"
            multiple
            placeholder="请选择"
          >
          </el-input>
        </template>
      </el-table-column>
      <el-table-column prop="organizationalUnit" label="出生年月">
        <template slot-scope="scope">
          <!-- <el-input v-model="scope.row.organizationalUnit" placeholder="请选择">
          </el-input> -->
          <el-col :span="11">
            <el-date-picker
              type="date"
              placeholder="选择日期"
              v-model="scope.row.organizationalUnit"
              style="width: 150px"
            ></el-date-picker>
          </el-col>
        </template>
      </el-table-column>
      <el-table-column prop="fullAmount" label="从业经历">
        <template slot-scope="scope">
          <!-- <el-input
            v-model="scope.row.fullAmount"
            placeholder="请选择"
            clearable
          >
          </el-input> -->
          <el-button style="color: #00e077" @click="dialogFormVisible = true"
            >点击编辑</el-button
          >
        </template>
      </el-table-column>
      <el-table-column prop="trainingDepartment" label="学校">
        <template slot-scope="scope">
          <el-input
            placeholder="请输入学校名"
            clearable
            v-model="scope.row.trainingDepartment"
          ></el-input>
        </template>
      </el-table-column>
      <el-table-column prop="trainingDepartment" label="学历">
        <template slot-scope="scope">
          <el-input
            placeholder="请输入学历"
            clearable
            v-model="scope.row.trainers"
          ></el-input>
        </template>
      </el-table-column>
      <el-table-column prop="trainingDepartment" label="从业时间">
        <template slot-scope="scope">
          <!-- <el-input
            placeholder="请输入时间"
            clearable
            v-model="scope.row.trainingDepartment"
          ></el-input> -->
          <el-col :span="11">
            <el-date-picker
              placeholder="选择日期"
              v-model="scope.row.cost"
              style="width: 150px"
            ></el-date-picker>
          </el-col>
        </template>
      </el-table-column>

      <el-table-column label="操作">
        <template slot-scope="scope">
          <i
            style="width: 50px"
            class="el-icon-delete"
            @click="handleDelete(scope.$index, scope.row)"
          ></i>
          <i
            style="width: 50px"
            class="el-icon-circle-plus-outline"
            @click="add(scope.$index, scope.row)"
          ></i>
        </template>
      </el-table-column>
    </el-table>

    <!-- Dialog 对话框 -->
    <el-dialog title="编辑从业人员信息" :visible.sync="dialogFormVisible">
      <el-table
        :data="tableDatas"
        style="width: 100%"
        :header-cell-style="{
          background: '',
          color: '#000',
          fontSize: '16px',
          height: '55px',
        }"
      >
        <!-- <el-table-column prop="numbering" label="编号"></el-table-column> -->
        <el-table-column prop="title" label="开始时间">
          <template slot-scope="scope">
            <!-- <el-input
              v-model="scope.row.title"
              placeholder="请输入姓名"
              style="100px"
            ></el-input> -->
            <el-col :span="11">
              <el-date-picker
                type="date"
                placeholder="选择日期"
                v-model="scope.row.title"
                style="width: 500px"
              ></el-date-picker>
            </el-col>
          </template>
        </el-table-column>
        <el-table-column prop="trainingType" label="结束时间">
          <template slot-scope="scope">
            <!-- <el-input
              v-model=""
              placeholder=""
              v-model="scope.row.trainingType"
              placeholder="请选择"
              clearable
            ></el-input> -->
            <el-col :span="11">
              <el-date-picker
                type="date"
                placeholder="选择日期"
                v-model="scope.row.trainingType"
                style="width: 500px"
              ></el-date-picker>
            </el-col>
          </template>
        </el-table-column>
        <el-table-column prop="fullAmount" label="公司名称">
          <template slot-scope="scope">
            <el-input
              v-model="scope.row.fullAmount"
              placeholder="请选择"
              clearable
            >
            </el-input>
            <!-- <el-button style="color: #00e077" @click="dialogFormVisible = true"
              >点击编辑</el-button
            > -->
          </template>
        </el-table-column>

        <el-table-column label="操作">
          <template slot-scope="scope">
            <i
              style="width: 50px"
              class="el-icon-delete"
              @click="handleDeletelog(scope.$index, scope.row)"
            ></i>
            <i
              style="width: 50px"
              class="el-icon-circle-plus-outline"
              @click="addlog(scope.$index, scope.row)"
            ></i>
          </template>
        </el-table-column>
      </el-table>
      <div slot="footer" class="dialog-footer">
        <el-button @click="dialogFormVisible = false">取 消</el-button>
        <el-button type="primary" @click="dialogFormVisible = false"
          >修改</el-button
        >
      </div>
    </el-dialog>
  </div>
</template>

<script>
export default {
  name: "AdminwebService",

  data() {
    return {
      dialogFormVisible: false,
      tableDatas: [
        {
          title: "",
          trainingType: "",
          fullAmount: "",
        },
      ],
      tableData: [
        {
          numbering: "",
          title: "",
          trainingType: "",
          trainingForm: "",
          trainingPlanTime: "",
          organizationalUnit: "",
          fullAmount: "",
          trainingDepartment: "",
          trainers: "",
          trainingLocation: "",
          cost: "",
        },
      ],
    };
  },

  mounted() {},

  methods: {
    //新增方法
    addlog() {
      this.valNumer = this.valNumer + 1;
      var list = {
        numbering: "编号" + `-${this.tableDatas.length + 1}`,
        title: this.title,
        trainingType: this.trainingType,
        trainingForm: this.trainingForm,
        trainingPlanTime: this.trainingPlanTime,
        organizationalUnit: this.organizationalUnit,
        fullAmount: this.fullAmount,
        trainingDepartment: this.trainingDepartment,
        trainers: this.trainers,
        trainingLocation: this.trainingLocation,
        cost: this.cost,
      };
      this.tableDatas.push(list);
    },
    add() {
      this.valNumer = this.valNumer + 1;
      var list = {
        numbering: "编号" + `-${this.tableData.length + 1}`,
        title: this.title,
        trainingType: this.trainingType,
        trainingForm: this.trainingForm,
        trainingPlanTime: this.trainingPlanTime,
        organizationalUnit: this.organizationalUnit,
        fullAmount: this.fullAmount,
        trainingDepartment: this.trainingDepartment,
        trainers: this.trainers,
        trainingLocation: this.trainingLocation,
        cost: this.cost,
      };
      this.tableData.push(list);
    },

    //删除新增的某行数据
    handleDeletelog(index, row) {
      this.tableDatas.splice(index, 1);
      for (var i = index; i < this.tableDatas.length; i++) {
        //从某一行删除了编号，删除的编号后面的编号数据要依次减一，所以遍历删除编号后面的数据
        this.tableDatas[i].numbering =
          "编号" + `-${Number(this.tableDatas[i].numbering.split("-")[1]) - 1}`;
      }
    },
    handleDelete(index, row) {
      console.log(123);
      // this.CategoryTable.splice(index, 1);
      // console.log(index, row);
      this.tableData.splice(index, 1);
      for (var i = index; i < this.tableData.length; i++) {
        //从某一行删除了编号，删除的编号后面的编号数据要依次减一，所以遍历删除编号后面的数据
        this.tableData[i].numbering =
          "编号" + `-${Number(this.tableData[i].numbering.split("-")[1]) - 1}`;
      }
    },
  },
};
</script>

<style lang="sass" scoped></style>
